package org.lq.his.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.ws.rs.GET;

import org.lq.his.pojo.Allergy;
import org.lq.his.pojo.Patient;
import org.lq.his.service.AllergyService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/allergy")
public class AllergyController {

	@Resource
	private AllergyService allergyService;

	public void setAllergyService(AllergyService allergyService) {
		this.allergyService = allergyService;
	}
	
	@RequestMapping("/index")
	public String allergyIndex() throws Exception{
		
		return "allergy/allergyIndex";
	}
	
	@RequestMapping("/allergyFrom")
	public String allergyFrom() throws Exception{
		
		return "allergy/allergyFrom";
	}
	
	@RequestMapping("/allergyAll")
	@ResponseBody
	public List<Allergy> allergyAll() throws Exception{
		
		return allergyService.getAll();
	}
	
	@RequestMapping("/allergyList")
	@ResponseBody
	public Map<String, Object> allergyList(Integer page, Integer rows,@RequestParam(defaultValue="id") String sort,@RequestParam(defaultValue="asc") String order,Allergy condition) throws Exception{
		Map<String, Object> map = new HashMap<>();
		Integer start = (page - 1) * rows;
		List<Allergy> list = allergyService.getListByCondition(start, rows, condition, sort, order);
		Integer total = allergyService.getCountByCondition(condition);
		map.put("rows", list);
		map.put("total", total);
		return map;
	}
	
	@RequestMapping("/allergyAdd")
	@ResponseBody
	public Map<String, Object> allergyAdd(Allergy allergy) throws Exception{
		Map<String, Object> map = new HashMap<>();
		allergyService.add(allergy);
		map.put("result", true);
		return map;
	}
	
	@RequestMapping("/allergyId")
	@ResponseBody
	public Allergy getById(Integer id) throws Exception{
		
		return allergyService.getById(id);
	}
	
	@RequestMapping("/allergyEdit")
	@ResponseBody
	public Map<String, Object> allergyEdit(Allergy allergy) throws Exception{
		Map<String, Object> map = new HashMap<>();
		allergyService.update(allergy);
		map.put("result", true);
		return map;
	}
	
	@RequestMapping("/allergyEditState")
	@ResponseBody
	public Map<String, Object> allergydeleteByIds(Integer[] ids) throws Exception{
		Map<String, Object> map = new HashMap<>();
		allergyService.deleteByIds(ids);
		map.put("result", true);
		return map;
	}
}
